<?php

include_once(APP_URL.'protected/myUtil/EchoUtil.php');
class CheckUtil {

    public static function checkPostParam($code, $value, $checkZero) {
        if (!isset($_POST[$value])) {// key is null
            echo EchoUtil::msgError($code, 'param error: '.$value.' is null !');
            exit;
        }
        if (empty($_POST[$value])) {// key and value is null
            if ($checkZero) {
                if ($_POST[$value] == '0') {// value is null
                    return $_POST[$value];
                }
            }
            echo EchoUtil::msgError($code, 'param error: '.$value.' is empty !');
            exit;
        } else {
            return $_POST[$value];
        }
    }
   
    public static function checkGetParam($code, $value, $checkZero) {
        if (!isset($_GET[$value])) {// key is null
            echo EchoUtil::msgError($code, 'param error: '.$value.' is null !');
            exit;
        }
        if (empty($_GET[$value])) {// key and value is null
            if ($checkZero) {
                if ($_GET[$value] == '0') {// value is null
                    return $_GET[$value];
                }
            }
            echo EchoUtil::msgError($code, 'param error: '.$value.' is empty !');
            exit;
        } else {
            return $_GET[$value];
        }
    }

}
	